<template>
  <view class="page">
    <view class="nav">
      <view class="nav_panel"
            v-for="(item, index) in dataList"
            :key="index">
        <view class="nav_item">
          <view class="left">{{item.title}}</view>
          <view class="right_text"
                @click="item.isCollapse = !item.isCollapse">
            <view class="arrow"
                  :class="item.isCollapse ? 'top': 'bottom'"></view>
          </view>
        </view>
        <view v-if="item.isCollapse && item.children"
              class="nav_item_children">
          <view class="nav_item"
                v-for="(dd, ind) in item.children"
                :key="ind"
                @click.stop="navigateTo(dd.path)">
            <view class="left">{{dd.title}}</view>
            <view class="right_text">
              <view class="arrow right"></view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script> 
export default {
  data () {
    return {
      dataList: [
        {
          title: '树', isCollapse: true, children: [
            { title: '紧凑树', path: '/pages/tree/compactBox' },
            { title: '生态图', path: '/pages/tree/dendrogram' },
            { title: '脑图树', path: '/pages/tree/mindmap' },
            { title: '缩进树', path: '/pages/tree/indented' },
            { title: '辐射树', path: '/pages/tree/radialtree' },
            { title: '定制树图样式', path: '/pages/tree/customItemTree' },
          ]
        }
      ]
    }
  },
  methods: {
    navigateTo (url) {
      uni.navigateTo({ url: url })
    }
  }
}
</script>

<style lang="scss" scoped>
page,
.page {
  width: 100%;
  height: 100%;
}
.nav {
  .nav_panel {
    .nav_item {
      padding: 20rpx 10px;
      border-radius: 10rpx;
      color: #333;
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #f2f2f2;
      .right_text {
        padding: 20rpx;
      }
    }
    .nav_item_children {
      padding-left: 20rpx;
    }
  }
}
.arrow {
  width: 6px;
  height: 6px;
  text-align: center;
  border-top: 1px solid #999;
  border-right: 1px solid #999;
  transition: all 0.5s;
  &.right {
    transform: rotate(45deg);
  }
  &.bottom {
    transform: rotate(135deg);
  }
  &.top {
    transform: rotate(-45deg);
  }
}
</style>
